#if _DEBUG

#include <cppunit/config/SourcePrefix.h>
#include "ShortcutTableTest.h"

#include <iostream>

using namespace std;

void ShortcutTableTest::setUp()
{
}

void ShortcutTableTest::tearDown()
{
}

CPPUNIT_TEST_SUITE_REGISTRATION( ShortcutTableTest );

void ShortcutTableTest::testPreInsert()
{
	ShortcutTable sc_table;

	CPPUNIT_ASSERT(0 == sc_table.GetAllAssign().size());
	CPPUNIT_ASSERT(0 == sc_table.GetAllCall().size());
	CPPUNIT_ASSERT(0 == sc_table.GetAllIf().size());
	CPPUNIT_ASSERT(0 == sc_table.GetAllWhile().size());
	CPPUNIT_ASSERT(0 == sc_table.GetAllConstant().size());
}

void ShortcutTableTest::testInsert()
{
	ShortcutTable sc_table;

	CPPUNIT_ASSERT(sc_table.InsertAssign(1));
	CPPUNIT_ASSERT(sc_table.InsertAssign(2));
	CPPUNIT_ASSERT(!sc_table.InsertAssign(1));

	CPPUNIT_ASSERT(sc_table.InsertCall(3));
	CPPUNIT_ASSERT(sc_table.InsertWhile(4));

	CPPUNIT_ASSERT(sc_table.InsertConstant(3));
	CPPUNIT_ASSERT(sc_table.InsertConstant(2));
	CPPUNIT_ASSERT(sc_table.InsertConstant(5));
	CPPUNIT_ASSERT(!sc_table.InsertConstant(5));
	CPPUNIT_ASSERT(!sc_table.InsertConstant(5));
	CPPUNIT_ASSERT(!sc_table.InsertConstant(5));
	CPPUNIT_ASSERT(sc_table.InsertConstant(1));
}

void ShortcutTableTest::testUnionAllStatement()
{
	ShortcutTable sc_table;
	sc_table.InsertAssign(1);
	sc_table.InsertAssign(2);
	sc_table.InsertCall(1);
	sc_table.InsertCall(2);
	sc_table.InsertCall(3);
	sc_table.InsertWhile(4);
	sc_table.InsertConstant(3);
	sc_table.InsertConstant(2);

	INTEGER_ARRAY statements = sc_table.GetAllStatement();
	
	CPPUNIT_ASSERT(statements.end() == statements.find(0));
	CPPUNIT_ASSERT(1 == *(statements.find(1)));
	CPPUNIT_ASSERT(2 == *(statements.find(2)));
	CPPUNIT_ASSERT(3 == *(statements.find(3)));
	CPPUNIT_ASSERT(4 == *(statements.find(4)));
	CPPUNIT_ASSERT(statements.end() == statements.find(5));

	CPPUNIT_ASSERT(4 == statements.size());
	CPPUNIT_ASSERT(1 == sc_table.GetAllCall().size());
}

void ShortcutTableTest::testPostInsert()
{
	ShortcutTable sc_table;
	sc_table.InsertAssign(1);
	sc_table.InsertAssign(2);
	sc_table.InsertCall(3);
	sc_table.InsertWhile(4);
	sc_table.InsertConstant(3);
	sc_table.InsertConstant(2);
	sc_table.InsertConstant(5);
	sc_table.InsertConstant(1);

	CPPUNIT_ASSERT(2 == sc_table.GetAllAssign().size());
	CPPUNIT_ASSERT(1 == sc_table.GetAllCall().size());
	CPPUNIT_ASSERT(0 == sc_table.GetAllIf().size());
	CPPUNIT_ASSERT(1 == sc_table.GetAllWhile().size());
	CPPUNIT_ASSERT(4 == sc_table.GetAllConstant().size());
}

void ShortcutTableTest::testGetStatementType()
{
	ShortcutTable sc_table;
	sc_table.InsertAssign(1);
	sc_table.InsertAssign(2);
	sc_table.InsertCall(3);
	sc_table.InsertWhile(4);
	sc_table.InsertConstant(3);
	sc_table.InsertConstant(2);
	sc_table.InsertConstant(5);
	sc_table.InsertConstant(1);

	CPPUNIT_ASSERT(ASSIGN == sc_table.GetStatementType(1));
	CPPUNIT_ASSERT(ASSIGN == sc_table.GetStatementType(2));
	CPPUNIT_ASSERT(CALL == sc_table.GetStatementType(3));
	CPPUNIT_ASSERT(WHILE == sc_table.GetStatementType(4));
}

#endif